package com.cal.utms.util;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.cal.utms.entity.Accounting;
import com.cal.utms.entity.AuidLog;
import com.cal.utms.entity.ComplianceRecipientsEmail;
import com.cal.utms.entity.CreditRating;
import com.cal.utms.entity.Csedownload;
import com.cal.utms.entity.Custodian;
import com.cal.utms.entity.CustodianContactPerson;
import com.cal.utms.entity.Customer;
import com.cal.utms.entity.CustomerBankAccount;
import com.cal.utms.entity.CustomerCodeSerial;
import com.cal.utms.entity.CustomerContactPerson;
import com.cal.utms.entity.CustomerEmail;
import com.cal.utms.entity.CustomerInvestment;
import com.cal.utms.entity.CustomerJointAppicant;
import com.cal.utms.entity.CustomerPledge;
import com.cal.utms.entity.CustomerRedemptionRequest;
import com.cal.utms.entity.CustomerTransactionLog;
import com.cal.utms.entity.DailyFigure;
import com.cal.utms.entity.Deal;
import com.cal.utms.entity.DealDailyInterest;
import com.cal.utms.entity.DealInstrumentMap;
import com.cal.utms.entity.DealType;
import com.cal.utms.entity.Dealer;
import com.cal.utms.entity.DelevaryMethod;
import com.cal.utms.entity.Fund;
import com.cal.utms.entity.FundInstrumentMap;
import com.cal.utms.entity.FundIssuerMap;
import com.cal.utms.entity.FundManager;
import com.cal.utms.entity.FundManagerContactPerson;
import com.cal.utms.entity.HolidayCalendar;
import com.cal.utms.entity.Instrument;
import com.cal.utms.entity.InstrumentCouponDate;
import com.cal.utms.entity.InstrumentFloatingRate;
import com.cal.utms.entity.InstrumentTransaction;
import com.cal.utms.entity.InstrumentType;
import com.cal.utms.entity.IssuerBankAccount;
import com.cal.utms.entity.IssuerContactPerson;
import com.cal.utms.entity.IssuerType;
import com.cal.utms.entity.Issuer;
import com.cal.utms.entity.Issuercodemapping;
import com.cal.utms.entity.Journalentry;
import com.cal.utms.entity.Menu;
import com.cal.utms.entity.MenuItem;
import com.cal.utms.entity.MoneyTransaction;
import com.cal.utms.entity.Payment;
import com.cal.utms.entity.PaymentReceiptView;
import com.cal.utms.entity.Permission;
import com.cal.utms.entity.PlacementSheet;
import com.cal.utms.entity.PlacementSheetRecord;
import com.cal.utms.entity.Receipt;
import com.cal.utms.entity.RedemptionReqToRedemtion;
import com.cal.utms.entity.SaledealMapping;
import com.cal.utms.entity.Screen;
import com.cal.utms.entity.ScreenConfirmation;
import com.cal.utms.entity.SeqGen;
import com.cal.utms.entity.SettlementMethod;
import com.cal.utms.entity.SystemConfiguration;
import com.cal.utms.entity.User;
import com.cal.utms.entity.UserGroup;
import com.cal.utms.entity.UserGroupScreen;
import com.cal.utms.entity.UserGroupScreenPK;

public class HibernateUtil {

	private static final SessionFactory sessionFactory;
	static {
		try {
			AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration().addPackage("com.cal.utms.entity");
			annotationConfiguration.addAnnotatedClass(User.class);
			annotationConfiguration.addAnnotatedClass(UserGroup.class);
			annotationConfiguration.addAnnotatedClass(Custodian.class);
			annotationConfiguration.addAnnotatedClass(Fund.class);
			annotationConfiguration.addAnnotatedClass(DealType.class);
			annotationConfiguration.addAnnotatedClass(IssuerType.class);
			annotationConfiguration.addAnnotatedClass(Issuer.class);
			annotationConfiguration.addAnnotatedClass(FundInstrumentMap.class);
			annotationConfiguration.addAnnotatedClass(CustodianContactPerson.class);
			annotationConfiguration.addAnnotatedClass(FundManager.class);
			annotationConfiguration.addAnnotatedClass(FundManagerContactPerson.class);
			annotationConfiguration.addAnnotatedClass(CreditRating.class);
			annotationConfiguration.addAnnotatedClass(Customer.class);
			annotationConfiguration.addAnnotatedClass(CustomerBankAccount.class);
			annotationConfiguration.addAnnotatedClass(CustomerInvestment.class);
			annotationConfiguration.addAnnotatedClass(CustomerCodeSerial.class);
			annotationConfiguration.addAnnotatedClass(CustomerContactPerson.class);
			annotationConfiguration.addAnnotatedClass(CustomerEmail.class);
			annotationConfiguration.addAnnotatedClass(CustomerJointAppicant.class);
			annotationConfiguration.addAnnotatedClass(InstrumentType.class);
			annotationConfiguration.addAnnotatedClass(Instrument.class);
			annotationConfiguration.addAnnotatedClass(IssuerBankAccount.class);
			annotationConfiguration.addAnnotatedClass(IssuerContactPerson.class);
			annotationConfiguration.addAnnotatedClass(SeqGen.class);
			annotationConfiguration.addAnnotatedClass(Deal.class);
			annotationConfiguration.addAnnotatedClass(InstrumentCouponDate.class);
			annotationConfiguration.addAnnotatedClass(InstrumentFloatingRate.class);
			annotationConfiguration.addAnnotatedClass(HolidayCalendar.class);
			annotationConfiguration.addAnnotatedClass(DealInstrumentMap.class);
			annotationConfiguration.addAnnotatedClass(InstrumentTransaction.class);
			annotationConfiguration.addAnnotatedClass(SystemConfiguration.class);
			annotationConfiguration.addAnnotatedClass(ScreenConfirmation.class);
			annotationConfiguration.addAnnotatedClass(MoneyTransaction.class);
			annotationConfiguration.addAnnotatedClass(RedemptionReqToRedemtion.class);
			annotationConfiguration.addAnnotatedClass(CustomerRedemptionRequest.class);
			annotationConfiguration.addAnnotatedClass(Receipt.class);
			annotationConfiguration.addAnnotatedClass(Menu.class);
			annotationConfiguration.addAnnotatedClass(MenuItem.class);
			annotationConfiguration.addAnnotatedClass(Screen.class);
			annotationConfiguration.addAnnotatedClass(UserGroupScreen.class);
			annotationConfiguration.addAnnotatedClass(UserGroupScreenPK.class);
			annotationConfiguration.addAnnotatedClass(Permission.class);
			annotationConfiguration.addAnnotatedClass(Payment.class);
			annotationConfiguration.addAnnotatedClass(CustomerTransactionLog.class);
			annotationConfiguration.addAnnotatedClass(CustomerPledge.class);
			annotationConfiguration.addAnnotatedClass(ComplianceRecipientsEmail.class);
			annotationConfiguration.addAnnotatedClass(PaymentReceiptView.class);
			annotationConfiguration.addAnnotatedClass(AuidLog.class);
			annotationConfiguration.addAnnotatedClass(PlacementSheet.class);
			annotationConfiguration.addAnnotatedClass(PlacementSheetRecord.class);
			annotationConfiguration.addAnnotatedClass(Csedownload.class);
			annotationConfiguration.addAnnotatedClass(Issuercodemapping.class);
			annotationConfiguration.addAnnotatedClass(Accounting.class);
			annotationConfiguration.addAnnotatedClass(Journalentry.class);
			annotationConfiguration.addAnnotatedClass(DailyFigure.class);
			annotationConfiguration.addAnnotatedClass(DealDailyInterest.class);
			annotationConfiguration.addAnnotatedClass(FundIssuerMap.class);
			annotationConfiguration.addAnnotatedClass(SettlementMethod.class);
			annotationConfiguration.addAnnotatedClass(Dealer.class);
			annotationConfiguration.addAnnotatedClass(DelevaryMethod.class);
			annotationConfiguration.addAnnotatedClass(SaledealMapping.class);
			sessionFactory = annotationConfiguration.configure().buildSessionFactory();
		} catch (Throwable ex) {
			System.err.println("Failed to create sessionFactory object." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSession() throws HibernateException {
		return sessionFactory;
	}

}
